package com.sdk.service.impl;

import com.coment.dto.ApiNotify;
import com.coment.dto.LiveData;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class ApiNotifyServiceImpl {
   @Resource
   private MongoTemplate mongoTemplate;
   @Value("${spring.application.name}")
   private String appName;

   @Async
   public void saveApiNotify(ApiNotify apiNotify) {
      LiveData.ApiType apiType = apiNotify.getApiType();
      String pushType = apiNotify.getPushType();
      String tableName = "%s.%s.%s".formatted(this.appName, apiType.getValue(), pushType);
      this.mongoTemplate.save(apiNotify, tableName);
   }
}
